package asteroids.entity;

import java.awt.Graphics;

import asteroids.engine.Utils;

/**
 * Attaches to its ship and holds the same relative position and rotation for
 * its lifespan Used to add window dressing to the ship outlines
 * 
 * @author whitecd1
 */
public class ShipIcing extends Icing
{
    private Ship ship;

    public ShipIcing(double x, double y, Ship ship, Utils.PolarCoordinate[] shape)
    {
        super(x, y, true, shape);
        this.ship = ship;
    }

    public ShipIcing(Ship ship, Utils.PolarCoordinate[] shape)
    {
        this(ship.getXPosition(), ship.getYPosition(), ship, shape);
    }

    public void update()
    {
        if( !ship.isAlive() )
        {
            destroy();
        }
        x_position = ship.getXPosition();
        y_position = ship.getYPosition();
        rotation = ship.getRotation();
        super.update();
    }

    public void draw(Graphics g)
    {
        if( ship.isAlive() && Math.abs(x_position - ship.getXPosition()) < 1
                && Math.abs(y_position - ship.getYPosition()) < 1 )
        {
            // color = ship.color;
            super.draw(g);
        }
    }

    public String toString()
    {
        return "ShipIcing";
    }
}
